import { _decorator } from "cc";
import { ecs } from "db://oops-framework/libs/ecs/ECS";
import { CCVMParentComp } from "db://oops-framework/module/common/CCVMParentComp";
import { smc } from "../../common/ecs/SingletonModuleComp";

const { ccclass, property } = _decorator;

/** 游戏主界面 */
@ccclass('MainViewComp')
@ecs.register('MainView', false)
export class MainViewComp extends CCVMParentComp {
    /** 脚本控制的界面 MVVM 框架绑定数据 */
    data: any = {};
    onBind() {
        this.onRegisterEvent(this.get("toggle_wujiang"), this.onToggle1Click);
        this.onRegisterEvent(this.get("toggle_zhuanbei"), this.onToggle2Click);
        this.onRegisterEvent(this.get("toggle_zhandou"), this.onToggle3Click);
        this.onRegisterEvent(this.get("toggle_baoxiang"), this.onToggle4Click);
        this.onRegisterEvent(this.get("toggle_fuben"), this.onToggle5Click);
    }

    private onToggle1Click() {
        this.changePage(1);
    }

    private onToggle2Click() {
        console.log("onToggle2Click");
    }

    private onToggle3Click() {
        console.log("onToggle3Click");
    }   

    private onToggle4Click() {
        console.log("onToggle4Click");
    }
    
    private onToggle5Click() {
        console.log("onToggle5Click");
    }
    changePage(key: number) {
        switch (key) {
            case 1:
                smc.account.loadRolePage(() => {
                    this.get("node_guan")!.active = false;
                    this.closeOther();
                });
                break;
            case 2:
                this.get("page_zhuanbei").active = true;
                break;
            case 3:
                this.get("page_zhandou").active = true;
                break;
            case 4:
                this.get("page_baoxiang").active = true;
                break;
            case 5:
                this.get("page_fuben").active = true;
                break;
        }
    }
    private closeOther() {}
    /** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
    reset() {
        this.node.destroy();
    }

}